import 'package:common/common.dart';
import 'package:common/entity/user_entity.dart';

/// 公用用户信息Provider
/// 1，判断是否登录
/// 2，提供用户信息
/// 3，提供用户信息编辑
final userProvider = ChangeNotifierProvider((_) => UserProvider(null));

class UserProvider extends ChangeNotifier {
  UserEntity? _user;

  UserProvider(UserEntity? user) {
    _user = user;
  }

  bool get isLogin {
    if (_user == null) {
      return false;
    }
    return true;
  }

  void login(UserEntity user) {
    _user = user;
    notifyListeners();
  }

  void logout() {
    _user = null;
    notifyListeners();
  }
}
